package com.yonyou.h5packing;

import android.graphics.PixelFormat;
import android.os.Bundle;
import android.os.Process;
import android.support.annotation.Nullable;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

import com.yonyou.common.base.BaseActivity;
import com.yonyou.h5packing.constant.Constants;
import com.yonyou.web.views.ProgressBarWebView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends BaseActivity {

    @BindView(R.id.progressBarWebView)
    ProgressBarWebView mProgressBarWebView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        getWindow().setFormat(PixelFormat.TRANSLUCENT);

        mProgressBarWebView.loadUrl(Constants.HTTP_URL);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mProgressBarWebView.back()) {
                return true;
            } else {
                return super.onKeyDown(keyCode, event);
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 连续点击两次退出程序;
     */
    private long exitTimeMillis = System.currentTimeMillis();

    @Override
    public void onBackPressed() {
        if (System.currentTimeMillis() - exitTimeMillis == 0 || System.currentTimeMillis() - exitTimeMillis > 1000) {
            exitTimeMillis = System.currentTimeMillis();
            Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_LONG).show();
            return;
        } else {
            Process.killProcess(Process.myPid());//退出
            System.exit(0);
        }
    }
}
